<template>
  <div class='aui-card--fill scroll-box card-box'>
    <div class='pane-shell'>
      <el-form :model="dataForm"
               v-loading="dataListLoading"
               ref="dataForm"
               label-position="left"
               @keyup.enter.native="dataFormSubmitHandle()"
               label-width="130px">
        <el-form-item prop="settingStatus"
                      label="app注册状态">
          <el-switch v-model="dataForm.settingStatus"
                     :active-value="1"
                     :inactive-value="0"
                     active-color="#13ce66"
                     inactive-color="#ff4949"
                     @change="setStatus($event)">
          </el-switch>
        </el-form-item>
      </el-form>
      <div class="header">
        <el-button type="primary"
                   @click="dataFormSubmitHandle">修改</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import minFormValidate from '@/mixins/form-validate'
import debounce from 'lodash/debounce'
export default {
  mixins: [mixinViewModule, minFormValidate],
  name: '',
  data () {
    return {
      mixinViewModuleOptions: {
        getDataInfoURL: '' // 数据详情，API地址
      },
      dataForm: {
        settingStatus: 0
      }
    }
  },
  components: {
  },
  computed: {
  },
  mounted () {
    this.getInfo()
  },
  methods: {
    getInfo () {
      this.getData({
        url: '/tb/register/getregisterSettings'
      }).then((res) => {
        if (res.code !== 0) {
          return
        }

        this.dataForm = res.data ? res.data : this.dataForm
      })
    },
    setStatus (data) {
      this.dataForm.settingStatus = data
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.postData({ url: '/tb/register/registerSettings' }).then(res => {
            if (res.code !== 0) {
              return false
            }
            this.dataForm = {}
            this.getInfo()
            this.$message.success('修改成功')
          })
        }
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>
<style lang="scss" scoped>
.header {
  width: 100%;
  text-align: center;
  margin-bottom: 20px;
}
</style>
